package com.asset.inventory.utils

import com.asset.inventory.base.BaseApp
import com.asset.inventory.kt.getPreferences
import com.asset.inventory.kt.open

/**
 *    @author : sibb
 *    date   : 21-4-7
 *    desc   :
 */
object SpHelper{

    /**
     * 保存token
     */
    fun saveToken(token: String){
        BaseApp.instance.applicationContext.getPreferences().open {
            putString("Authentication",token)
        }
    }

    /**
     * 获取token
     */
    fun getToken(): String{
        return BaseApp.instance.applicationContext.getPreferences().getString("Authentication","")!!
    }

    /**
     * 保存用户名
     */
    fun saveUserName(name: String){
        BaseApp.instance.applicationContext.getPreferences().open {
            putString("USER_NAME",name)
        }
    }

    /**
     * 获取用户名
     */
    fun getUserName(): String{
        return BaseApp.instance.applicationContext.getPreferences().getString("USER_NAME","")!!
    }

    /**
     * 保存账户密码
     */
    fun savePassword(password: String){
        BaseApp.instance.applicationContext.getPreferences().open {
            putString("PASSWORD",password)
        }
    }

    /**
     * 获取账户密码
     */
    fun getPassword(): String{
        return BaseApp.instance.applicationContext.getPreferences().getString("PASSWORD","")!!
    }
}